package com.station.administrators.controller;

import com.open.capacity.common.web.Result;
import com.open.capacity.common.model.ActivityModel;
import com.station.administrators.service.PlatformActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 平台活动管理
 * @Description: TODO
 * @date 2021/6/25/9:48
 */
@Api(tags = "平台活动管理")
@RestController
@RequestMapping("/platformActivity")
public class PlatformActivityController {
    @Autowired
    private PlatformActivityService platformActivityService;
    @ApiOperation("添加平台活动")
    @PostMapping("/add")
    public Object add(@RequestBody ActivityModel activity){
        platformActivityService.add(activity);
        return Result.succeed("添加成功！");
    }
    @ApiOperation("修改平台活动")
    @PostMapping("/update")
    public Object update( ActivityModel activity){
        platformActivityService.update(activity);
        return Result.succeed("修改成功！");
    }
    @ApiOperation("删除平台活动")
    @PostMapping("/delete")
    public Object delete(Long id){
        platformActivityService.delete(id);
        return Result.succeed("删除成功！");
    }
    @ApiOperation("根据id查询平台活动")
    @GetMapping("/findById")
    public Object findById(Long id){
        ActivityModel activity=platformActivityService.findById(id);
        return Result.succeed(activity,"a");
    }
    @ApiOperation("查询平台活动")
    @GetMapping("/findAll")
    public Object findAll(ActivityModel activity){
        List<ActivityModel> activityList =platformActivityService.findAll(activity);
        Integer count=platformActivityService.getCount(activity);
        Map<String,Object> map=new HashMap<>();
        map.put("activity",activityList);
        map.put("count",count);
        return Result.succeed(map,"");
    }
}
